var count=0;
var opentype=0;
var newwindow = null;


function isNumber(sValue) {
	return isMakeOf(sValue,"+-.0123456789");
}

function FormisNumber(ctrlobj){
	if(isNumber(ctrlobj.value)) 
		return true;
	else {
		alert("please input digit!");
		return false;
	}
}


function isMakeOf( sValue, sElement ){
	var nIndex = 0;
	sValue = sValue.toUpperCase();
	sElement = sElement.toUpperCase();
	
	for (nIndex=0; nIndex<sValue.length; nIndex++)  
    {  
        cCheck = sValue.charAt(nIndex);
        if (sElement.indexOf( cCheck )< 0) {  
			return false;
        }  
    }
	return true;
}

function OrderBy(orderfield,ordermode)
{
	window.formIon.ordermode.value=ordermode;
	window.formIon.orderfield.value=orderfield;
	window.formIon.submit();
}

function IonOpenWindow(sURL,vFormName,sFeatures)
{
			if(vFormName==null || vFormName=="")
				vFormName="ion";
			if(sFeatures == null || sFeatures=="");
				sFeatures ="dialogWidth:600px; dialogHeight:500px; dialogLeft:100px; dialogTop:50px; status:no; directories:yes;scrollbars:yes;Resizable=no;";
			if(opentype==1)
			{
				retval = window.showModalDialog(sURL,vFormName,sFeatures);
				if(retval != null)				
					window.formIon.submit();
			}
			else  {
					newwindow = window.open(sURL,vFormName,"menubar=no,toolbar=no,scrollbars=yes,width=600,height=500,status=0,left=100,top=50");
					newwindow.focus();
			}
}

function OpenWin(url,formname)
{
		if(formname==null || formname=="")
			formname="ion_small";		
		if(opentype==1) {
				retval = window.showModalDialog(url,formname,"dialogWidth:350px; dialogHeight:250px; dialogLeft:200px; dialogTop:100px; status:no; directories:yes;scrollbars:yes;Resizable=no;");
				if(retval!=null)
					window.location.reload();
		} 
		else {
			newwindow=window.open(url,formname,"menubar=no,toolbar=no,scrollbars=no,width=350,height=250,status=0,left=200,top=100");
			newwindow.focus();
		}
}

function add_Ion(hrefstr,actionurl,newpara,name,feature){		
		if(opentype==1)
			IonOpenWindow(hrefstr+"?actionurl="+actionurl+"&catid="+window.formIon.catid.value+"&"+newpara+"="+window.formIon.id.value,name,feature);
		else
			IonOpenWindow(actionurl+"?catid="+window.formIon.catid.value+"&"+newpara+"="+window.formIon.id.value,name,feature);
		
}


function addIon(hrefstr,actionurl,name,feature){		
		if(opentype==1)
			IonOpenWindow(hrefstr+"?actionurl="+actionurl+"&catid="+window.formIon.catid.value,name,feature);
		else
			IonOpenWindow(actionurl+"?catid="+window.formIon.catid.value,name,feature);
		
}

function selectlist(number) {	
	var selectid;
	var selecttext;
	selectid="";
	selecttext="";
	count=0;
	var selectitem="";
	if(number==null)
		number=2;
	for(i=0;i<(window.table1.getRowCount());i++)
	{
		if (window.table1.isRowSelected(i)==true){
			count=count+1;
			selectid=window.table1.getCell(i,0);
			selectitem+=selectid+",";
			selecttext=window.table1.getCell(i,number);
		}
	}
	window.formIon.objid.value=selectid;
	window.formIon.objtext.value=selecttext;
	return selectitem;
}

function seeIon(actionurl,titlename)
{
	selectlist();
	if(titlename==null || titlename=="")
		titlename="object";
	if(count>1) {
		window.alert("You can not view mulitype "+titlename+"! Please select one "+titlename+" and opertion!");
	} else {
		if(window.formIon.objid.value==""){
			window.alert("please select "+titlename+"!");
		} else {
			location.href=actionurl+"?catid="+window.formIon.catid.value+"&paperid="+window.formIon.objid.value;
		}
	}
}
 
function changeIon(actionurl,titlename,number)
{
	selectlist(number);
	if(titlename==null || titlename=="")
		titlename="object";
	if(count>1) {
		window.alert("You can not view mulitype "+titlename+"! Please select one "+titlename+" and opertion!");
	} else {
		if(window.formIon.objid.value==""){
			window.alert("please select "+titlename+"!");
		} else {
			if(window.formIon.objtext.value=="0")
				window.alert(titlename+" have no"+titlename+"!");		
			else
				location.href=actionurl+"?catid="+window.formIon.catid.value+"&id="+window.formIon.objid.value;
		}
	}
}

function editIon(hrefstr,actionurl,titlename,name,feature)
{
	selectlist();
	if(titlename==null || titlename=="")
		titlename="object";
	if(count>1) {
		window.alert("You can not view mulitype "+titlename+"! Please select one "+titlename+" and opertion!");
	} else {
		if(window.formIon.objid.value==""){
			window.alert("please select "+titlename+"!");
		} else {
			if(opentype==1)
				IonOpenWindow(hrefstr+"?actionurl="+actionurl+"&catid="+window.formIon.catid.value+"&id="+window.formIon.objid.value,name,feature);
			else
				IonOpenWindow(actionurl+"?catid="+window.formIon.catid.value+"&id="+window.formIon.objid.value,name,feature);
		}
	}
}

function do_Input(hrefstr,actionurl,para,name,feature)
{
		var str=window.showModalDialog("../fms/fmsSelectFrame.jsp?module=cms&path=excel");	
		if(str!=null) {
			if(opentype==1)
				IonOpenWindow(hrefstr+"?actionurl="+actionurl+"&catid="+window.formIon.catid.value+"&"+para+"="+window.formIon.id.value+"&filename="+str,name,feature);
			else
				IonOpenWindow(actionurl+"?catid="+window.formIon.catid.value+"&"+para+"="+window.formIon.id.value+"&filename="+str,name,feature);			
 		} 		
}

function doInput(hrefstr,actionurl,name,feature)
{
		var str=window.showModalDialog("../fms/fmsSelectFrame.jsp?module=cms&path=excel");	
		if(str!=null) {
			if(opentype==1)
				IonOpenWindow(hrefstr+"?actionurl="+actionurl+"&catid="+window.formIon.catid.value+"&filename="+str,name,feature);
			else
				IonOpenWindow(actionurl+"?catid="+window.formIon.catid.value+"&filename="+str,name,feature);			
 		} 		
}

function doOutput(hrefstr,actionurl,titlename,name,feature)
{
	var deleteitem=selectlist();
	if(titlename==null || titlename=="")
		titlename="object";
	if(count>1) {
		if(!window.confirm("Do you want to export "+titlename+"?"))
			return ;
	} else {		 
		if(window.formIon.objid.value=="" | window.formIon.objid==null){
			window.alert("please select "+titlename+"!");	
			return ;
		} else {
			if(!window.confirm("Do you confirm to export "+titlename+" \""+window.formIon.objtext.value+"\"?"))
				return ;
		}
	}
	if(opentype==1)
		IonOpenWindow(hrefstr+"?actionurl="+actionurl+"&catid="+window.formIon.catid.value+"&id="+deleteitem,name,feature);	
	else
		IonOpenWindow(actionurl+"?catid="+window.formIon.catid.value+"&id="+deleteitem,name,feature);	
} 

function deleteIon(hrefstr,actionurl,titlename,name,feature)
{
	var deleteitem=selectlist();
	if(titlename==null || titlename=="")
		titlename="object";
	if(count>1) {
		if(!window.confirm("Do you want to delete "+titlename+"?"))
			return ;
	} else {		 
		if(window.formIon.objid.value=="" | window.formIon.objid==null){
			window.alert("please select "+titlename+"!");	
			return ;
		} else {
			if(!window.confirm("Do you confirm to delete "+titlename+" \""+window.formIon.objtext.value+"\"?"))
				return ;
		}
	}
	if(opentype==1)
		IonOpenWindow(hrefstr+"?actionurl="+actionurl+"&catid="+window.formIon.catid.value+"&id="+deleteitem,name,feature);	
	else
		IonOpenWindow(actionurl+"?catid="+window.formIon.catid.value+"&id="+deleteitem,name,feature);	
}

function selectIon(hrefstr,actionurl,titlename,name,feature)
{
	var deleteitem=selectlist();
	if(titlename==null || titlename=="")
		titlename="object";
	if(count>1) {
		if(!window.confirm("Do you want to add "+titlename+"?"))
			return ;
	} else {		 
		if(window.formIon.objid.value=="" | window.formIon.objid==null){
			window.alert("please select "+titlename+"!");	
			return ;
		} else {
			if(!window.confirm("Do you confirm add "+titlename+" \""+window.formIon.objtext.value+"\" ?"))
				return ;
		}
	}
	if(opentype==1)
		IonOpenWindow(hrefstr+"?actionurl="+actionurl+"&catid="+window.formIon.catid.value+"&id="+deleteitem,name,feature);	
	else
		IonOpenWindow(actionurl+"?catid="+window.formIon.catid.value+"&id="+deleteitem,name,feature);	
}

function gotopage(id)
{
	window.formIon.pageid.value=id;
	window.formIon.submit();
}

function closewindow(iValue)
{
	if(iValue==null)
		iValue==0;
 	var top=this;
 	if (parent) top=parent;
 	top.returnValue="OK";
 	top.close();
 	if(opentype==0)
 	{
 		if(iValue==0)
 			window.opener.formIon.submit();
 		else if(iValue==2)
 			window.opener.location.reload();
 	}
}

function changeOrder(hrefstr,actionurl,titlename,name,feature)
{
	var deleteitem=selectlist();
	if(titlename==null || titlename=="")
		titlename="onject";
	if(window.formIon.objid.value=="" || window.formIon.objid==null){
		window.alert("please select "+titlename+"!");	
		return ;
	}
	if(opentype==1)
		IonOpenWindow(hrefstr+"?actionurl="+actionurl+"&catid="+window.formIon.catid.value+"&id="+deleteitem,name,feature);	
	else
		IonOpenWindow(actionurl+"?catid="+window.formIon.catid.value+"&id="+deleteitem,name,feature);	
}
	
function Change_Category(hrefstr,actionurl,titlename,name,feature,modulecode) {
	var deleteitem=selectlist();
	if(titlename==null || titlename=="")
		titlename="object";
	if(modulecode==null || modulecode=="")
		modulecode="cms";
	if(count>1) {
		if(!window.confirm("Do you confirm change "+titlename+" to new category?"))
			return ;
	} else {		 
		if(window.formIon.objid.value=="" | window.formIon.objid==null){
			window.alert("please select "+titlename+"!");	
			return ;
		} else {
			if(!window.confirm("Are you sure to change "+titlename+" \""+window.formIon.objtext.value+"\" to new category?"))
				return ;
		}
	}
	var str=window.showModalDialog("../sys/sysSelectCategory.jsp?module="+modulecode+"&id=0");
	if(str!=null) {
		var intPos=str.indexOf(" ");
		var category=str.substring(0,intPos);
		var categoryname=str.substring(intPos+1);
		if(opentype==1)
			IonOpenWindow(hrefstr+"?actionurl="+actionurl+"&catid="+window.formIon.catid.value+"&id="+deleteitem+"&newcat="+category,name,feature);	
		else
			IonOpenWindow(actionurl+"?catid="+window.formIon.catid.value+"&id="+deleteitem+"&newcat="+category,name,feature);	
	}
}

function Copy_Category(hrefstr,actionurl,titlename,name,feature,modulecode) {
	var deleteitem=selectlist();
	if(titlename==null || titlename=="")
		titlename="object";
	if(modulecode==null || modulecode=="")
		modulecode="cms";
	if(count>1) {
		if(!window.confirm("Do you want to copy "+titlename+" to new category?"))
			return ;
	} else {		 
		if(window.formIon.objid.value=="" | window.formIon.objid==null){
			window.alert("please select "+titlename+"!");	
			return ;
		} else {
			if(!window.confirm("Are you sure to copy "+titlename+" \""+window.formIon.objtext.value+"\" to new category?"))
				return ;
		}
	}
	var str=window.showModalDialog("../sys/sysSelectCategory.jsp?module="+modulecode+"&id=0");
	if(str!=null) {
		var intPos=str.indexOf(" ");
		var category=str.substring(0,intPos);
		var categoryname=str.substring(intPos+1);
		if(opentype==1)
			IonOpenWindow(hrefstr+"?actionurl="+actionurl+"&catid="+window.formIon.catid.value+"&id="+deleteitem+"&newcat="+category,name,feature);	
		else
			IonOpenWindow(actionurl+"?catid="+window.formIon.catid.value+"&id="+deleteitem+"&newcat="+category,name,feature);	
	}
}

function check(hrefstr,actionurl,titlename,name,feature)
{
	var deleteitem=selectlist();
	if(titlename==null || titlename=="")
		titlename="object";
	if(window.formIon.objid.value=="" || window.formIon.objid==null){
		window.alert("please select "+titlename+"!");	
		return ;
	}
	if(opentype==1)
		IonOpenWindow(hrefstr+"?actionurl="+actionurl+"&catid="+window.formIon.catid.value+"&id="+deleteitem,name,feature);	
	else
		IonOpenWindow(actionurl+"?catid="+window.formIon.catid.value+"&id="+deleteitem,name,feature);	
}

